package net.randomice.emf.observables.demo.extlibrary.observables;

import java.util.List;
import java.util.Set;
import net.randomice.emf.observables.demo.extlibrary.Addressable;
import net.randomice.emf.observables.demo.extlibrary.ExtlibraryFactory;
import net.randomice.emf.observables.demo.extlibrary.ExtlibraryPackage;
import net.randomice.emf.observables.demo.extlibrary.Library;
import net.randomice.emf.observables.runtime.IObservableListObject;
import net.randomice.emf.observables.runtime.ObservableSetRootObjects;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.core.databinding.observable.set.IObservableSet;
import org.eclipse.core.databinding.observable.set.ListToSetAdapter;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
 * An Observable list wrapper for {@link Library}
 * @generated
 */
public class LibraryOL implements IObservableListObject<Library> {
	public final IObservableList o;

	public LibraryOL(IObservableList observableList) {
		Object type = observableList.getElementType();
		if (type instanceof EReference) {
			type = ((EReference) type).getEType().getInstanceClass();
		}
		Assert.isTrue(null == type || Library.class.equals(type));
		o = observableList;
	}

	@SuppressWarnings("unchecked")
	public List<Library> getList() {
		return (List<Library>) o;
	}

	public LibraryOO add(Library object) {
		getObservableObjects();
		o.add(object);
		return (LibraryOO) observableObjects.get(object);
	}

	public LibraryOO addNew() {
		return add(ExtlibraryFactory.eINSTANCE.createLibrary());
	}

	private IObservableSet listToSetAdapter = null;
	public IObservableSet getObservableSet() {
		if (null == listToSetAdapter) {
			listToSetAdapter = new ListToSetAdapter(o);
		}
		return listToSetAdapter;
	}

	private ObservableSetRootObjects<Library, LibraryOO> observableObjects = null;
	@SuppressWarnings("unchecked")
	public Set<LibraryOO> getObservableObjects() {
		if (null == observableObjects) {
			observableObjects = new ObservableSetRootObjects<Library, LibraryOO>(
					getObservableSet(), LibraryOO.class, LibraryOO.CREATOR);
		}
		return (Set<LibraryOO>) observableObjects;
	}

	public IObservableMap getMapFeature(EStructuralFeature feature) {
		if (ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS.equals(feature)) {
			return getAddress();
		}
		if (ExtlibraryPackage.Literals.LIBRARY__NAME.equals(feature)) {
			return getName();
		}
		if (ExtlibraryPackage.Literals.LIBRARY__PARENT_BRANCH.equals(feature)) {
			return getParentBranch().o;
		}
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	// features from type Addressable

	private IObservableMap address = null;
	public IObservableMap getAddress() {
		if (null == address) {
			address = EMFObservables.observeMap(getObservableSet(),
					ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS);
		}
		return address;
	}

	// features from type Library

	private IObservableMap name = null;
	public IObservableMap getName() {
		if (null == name) {
			name = EMFObservables.observeMap(getObservableSet(),
					ExtlibraryPackage.Literals.LIBRARY__NAME);
		}
		return name;
	}

	// ??? many feature in list

	// ??? many feature in list

	// ??? many feature in list

	// ??? many feature in list

	private LibraryOM<Library> parentBranch = null;
	public LibraryOM<Library> getParentBranch() {
		if (null == parentBranch) {
			parentBranch = new LibraryOM<Library>(Library.class, EMFObservables
					.observeMap(getObservableSet(),
							ExtlibraryPackage.Literals.LIBRARY__PARENT_BRANCH));
		}
		return parentBranch;
	}

	// ??? many feature in list

	// ??? many feature in list

}
